<template>
  <div class="getHistory">
    <el-form
        :inline="true"
        :model="searchParams"
        class="formInline"
        size="small"
    >
      <el-form-item label="操作时间">
        <el-date-picker
            style="width: 375px;"
            v-model="dateRange"
            type="datetimerange"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            @change="changeDate"
            value-format="yyyy-MM-dd HH:mm:ss"
            :default-time="['00:00:00', '23:59:59']">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="执行状态">
        <el-select v-model="searchParams.select1" placeholder="请选择">
          <el-option label="成功" value="01"></el-option>
          <el-option label="失败" value="02"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="操作人">
        <el-input
            class="inputClass"
            v-model="searchParams.input1"
            placeholder="操作人"
            :maxlength="50"
        ></el-input>
      </el-form-item>
      <el-form-item style="margin-bottom: 4px;">
        <el-button type="primary" @click="onSubmit">查询</el-button>
        <el-button type="primary" @click="onResize">重置</el-button>
      </el-form-item>
    </el-form>

    <tableList
        :showIndex="true"
        :loading="loading"
        border
        :total="pages.total"
        :keySet="keySet"
        :heightMin="heightMin"
        :tableData="listDetails"
        :paginationShow="true"
        :pageNumber="pages.current"
        :pageSize="pages.size"
        @handleSizeChange="handleSizeChange"
        @handleCurrentChange="handleCurrentChange"
    >
      <template #operateStatus1="{ row }">
        <div>
          {{ row.operateStatus }}
        </div>
      </template>
      <template #operateStatus2="{ row }">
        <div v-if="row.operateStatus == '成功'" @click="look(row)" class="worldBlueBtn">查看</div>
        <div v-else >
          <popCom :content="row.operateMsg"/>
        </div>
      </template>
    </tableList>

    <vxe-modal
        v-model="baseInfoShow"
        class="dialogClass nsrjbxxhqjlxq"
        title="纳税人基本信息获取记录详情"
        width="100%"
        min-width="900"
        height="500"
        style="overflow-y: auto;min-height: 500px;"
    >
      <template v-slot>
        <el-card class="cardWrap">
          <div slot="header" class="clearfix">
            <span>企业基本信息</span>
          </div>
          <div style="width: 100%">
            <el-row>
              <el-col :span="8">
                <div class="qiyeC">
                  <span>纳税人名称：</span>
                  <popCom :content="detailInfoDetail.nsrmc"/>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="qiyeC">
                  <span>纳税人识别号/统一社会信用代码：</span>
                  <popCom :content="detailInfoDetail.nsrsbh"/>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="qiyeC">
                  <span>登记序号：</span>

                  <popCom :content="detailInfoDetail.djxh"/>

                </div>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <div class="qiyeC">
                  <span>税收档案编号：</span>

                  <popCom :content="detailInfoDetail.ssdabh"/>

                </div>
              </el-col>
              <el-col :span="8">
                <div class="qiyeC">
                  <span>纳税人类型标签：</span>

                  <popCom :content="detailInfoDetail.nsrlx"/>

                </div>
              </el-col>
              <el-col :span="8">
                <div class="qiyeC">
                  <span>生产经营地址：</span>

                  <popCom :content="detailInfoDetail.scjydz"/>

                </div>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <div class="qiyeC">
                  <span>注册地邮政编码：</span>

                  <popCom :content="detailInfoDetail.zcdyzbm"/>

                </div>
              </el-col>
              <el-col :span="8">
                <div class="qiyeC">
                  <span>注册地联系电话：</span>

                  <popCom :content="detailInfoDetail.zcdlxdh"/>

                </div>
              </el-col>
              <el-col :span="8">
                <div class="qiyeC">
                  <span>法人名称（法定代表人姓名）：</span>

                  <popCom :content="detailInfoDetail.fddbrxm"/>

                </div>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <div class="qiyeC">
                  <span>登记注册类型（国标）：</span>

                  <popCom :content="detailInfoDetail.djzclxdm"/>

                </div>
              </el-col>
              <el-col :span="8">
                <div class="qiyeC">
                  <span>行业代码：</span>

                  <popCom :content="detailInfoDetail.hydm"/>

                </div>
              </el-col>
              <el-col :span="8">
                <div class="qiyeC">
                  <span>企业行业性质：</span>

                  <popCom :content="detailInfoDetail.qyhyxzdm"/>

                </div>
              </el-col>
            </el-row>

          </div>
        </el-card>
        <el-card class="cardWrap">
          <div slot="header" class="clearfix">
            <span>企业税务信息</span>
          </div>
          <div style="width: 100%">
            <el-row>
              <el-col :span="8">
                <div class="qiyeC">
                  <span>区县级税务机关代码：</span>

                  <popCom :content="detailInfoDetail.qxjswjgdm"/>

                </div>
              </el-col>
              <el-col :span="8">
                <div class="qiyeC">
                  <span>税务机关代码：</span>

                  <popCom :content="detailInfoDetail.zgswskfjdm"/>

                </div>
              </el-col>
              <el-col :span="8">
                <div class="qiyeC">
                  <span>税务机关名称：</span>

                  <popCom :content="detailInfoDetail.zgswskfjmc"/>

                </div>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <div class="qiyeC">
                  <span>开票方纳税人状态：</span>

                  <popCom :content="detailInfoDetail.nsrztdm"/>

                </div>
              </el-col>
              <el-col :span="8">
                <div class="qiyeC">
                  <span>纳税人类型标签有效期起：</span>

                  <popCom :content="detailInfoDetail.yxqq"/>
                </div>
              </el-col>
              <el-col :span="8">
                <div class="qiyeC">
                  <span>纳税人类型标签有效期止：</span>

                  <popCom :content="detailInfoDetail.yxqz"/>
                </div>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <div class="qiyeC">
                  <span>消费税纳税人类型：</span>
                  <popCom :content="detailInfoDetail.xfsnsrlxdm"/>
                </div>
              </el-col>
            </el-row>
          </div>
        </el-card>
        <el-card class="cardWrap">
          <div slot="header" class="clearfix">
            <span>企业财务信息</span>
          </div>
          <div style="width: 100%">
            <el-row>
              <el-col :span="8">
                <div class="qiyeC">
                  <span>财务负责人姓名：</span>
                  <popCom :content="detailInfoDetail.cwfzrxm"/>
                  <!-- <span class="colorGray">
                                        {{ detailInfoDetail.cwfzrxm }}
                                    </span> -->
                </div>
              </el-col>
              <el-col :span="8">
                <div class="qiyeC">
                  <span>账户名称：</span>
                  <popCom :content="detailInfoDetail.khhmc"/>

                  <!-- <span class="colorGray">
                                        {{ detailInfoDetail.khhmc }}
                                    </span> -->
                </div>
              </el-col>
              <el-col :span="8">
                <div class="qiyeC">
                  <span>账号：</span>
                  <popCom :content="detailInfoDetail.yhzh"/>
                  <!-- <span class="colorGray">
                                        {{ detailInfoDetail.yhzh }}
                                    </span> -->
                </div>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <div class="qiyeC">
                  <span>企业办税人员姓名：</span>
                  <popCom :content="detailInfoDetail.bsrxm"/>
                  <!-- <span class="colorGray">
                                        {{ detailInfoDetail.bsrxm }}
                                    </span> -->
                </div>
              </el-col>
              <el-col :span="8">
                <div class="qiyeC">
                  <span>新电票试点企业标识：</span>
                  <popCom :content="detailInfoDetail.xdpsdqybz"/>

                  <!-- <span class="colorGray">
                                        {{ detailInfoDetail.xdpsdqybz }}
                                    </span> -->
                </div>
              </el-col>
              <el-col :span="8">
                <div class="qiyeC">
                  <span>出口企业分类：</span>
                  <popCom :content="detailInfoDetail.ckqyfldm"/>
                  <!-- <span class="colorGray">
                                        {{ detailInfoDetail.ckqyfldm }}
                                    </span> -->
                </div>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <div class="qiyeC">
                  <span>总分机构类型：</span>
                  <popCom :content="detailInfoDetail.zfjglxdm"/>

                  <!-- <span class="colorGray">
                                        {{ detailInfoDetail.zfjglxdm }}
                                    </span> -->
                </div>
              </el-col>
              <el-col :span="8">
                <div class="qiyeC">
                  <span>银行营业网点：</span>
                  <popCom :content="detailInfoDetail.yhyywddm"/>

                  <!-- <span class="colorGray">
                                        {{ detailInfoDetail.yhyywddm }}
                                    </span> -->
                </div>
              </el-col>
            </el-row>
          </div>
        </el-card>
      </template>
    </vxe-modal>
    <vxe-modal
        v-model="ssflShow"
        class="dialogClass2"
        title="税收分类编码信息"
        :showFooter="true"
        width="100%"
    >
      <template v-slot>
        <tableList
            :showIndex="true"
            border
            :loading="loading2"
            :heightMin="300"
            :keySet="dialogSingleDataListKeyset"
            height="420"
            :tableData="singleDataList"
            :paginationShow="true"
            :total="ListPage.total"
            :pageNumber="ListPage.current"
            :pageSize="ListPage.size"
            @handleSizeChange="handlePageSizeChange"
            @handleCurrentChange="handlePageCurrentChange"
        ></tableList>

      </template>
      <template #footer>
        <el-button
            size="small"
            style="margin-right: 8px"
            @click="ssflShow = false"
        >
          关闭
        </el-button>
        <el-button
            size="small"
            type="primary"
            @click="detailExport"
        >
          导出
        </el-button>
      </template>
    </vxe-modal>
    <vxe-modal
        v-model="kyslShow"
        class="dialogClass"
        title="可用税率信息"
        width="80%"
        :showFooter="true"
    >
      <template v-slot>
        <tableList
            :showIndex="true"
            :loading="loading2"
            border
            :heightMin="120"
            :keySet="dialogSingleDataListKeyset2"
            height="420"
            :tableData="singleDataList2"
            :paginationShow="true"
            :total="ListPage.total"
            :pageNumber="ListPage.current"
            :pageSize="ListPage.size"
            @handleSizeChange="handlePageSizeChange"
            @handleCurrentChange="handlePageCurrentChange"
        >
          <template #slzsl="{ row }">
            <div>{{ row.slzsl || 0 }}</div>
          </template>
        </tableList>
      </template>
      <template #footer>
        <el-button
            style="margin-right: 8px"
            @click="kyslShow = false"
        >
          关闭
        </el-button>
        <el-button type="primary" @click="detailExport2">导出</el-button>
      </template>
    </vxe-modal>
  </div>
</template>

<script>
import mixinTable from '../../../mixin/mtable.js'
import tableList from '@/components/tableList/index.vue'
import {throttle} from 'lodash'
import popCom from "@/components/popCom.vue"
import {
  queryVmsAvalibleTaxRateLogDetail,
  getDetail,
  getBaseDetailPage,
  queryVmsAvalibleTaxRateLog,
  getBasePage,
  vmsEnterpriseInfoPage
} from '@/api/vmsEnterpriseInfo.js'
import {exportDetailList, exportVmsAvalibleTaxRateLogDetail} from '@/api/fileDownload.js'

export default {
  name: 'getHistory',
  mixins: [mixinTable],
  props: {
    source: {
      type: String,
      default: 'baseInfo',
    },
    heightMin: {
      type: Number,
      default: 150,
    },
  },
  data() {
    return {
      dateRange: ['', ''],
      lookRow: {},
      loading2: false,

      baseInfoShow: false,
      ssflShow: false,
      kyslShow: false,

      // date1: '',
      // date2: '',

      listDetails: [],

      detailInfoDetail: {},

      keySet: [
        {
          label: '操作时间',
          englishName: 'createTime',
        },

        {
          label: '执行状态',
          englishName: 'operateStatus',
          isSlot: true,
          slotName: 'operateStatus1',
        },
        {
          label: '时间戳',
          englishName: 'sjc'
        },
        {
          label: '总数量',
          englishName: 'logCount'
        },
        {
          label: '执行结果',
          englishName: 'operateStatus',
          isSlot: true,
          slotName: 'operateStatus2',
        },
        {
          label: '操作人',
          englishName: 'createUsername',
        },
      ],

      dialogSingleDataListKeyset: [
        {
          label: '父级编码',
          englishName: 'fjbm',
        },
        {
          label: '商品和服务税收分类合并编码',
          englishName: 'sphfwssflhbbm',
          width: 180,
        },
        {
          label: '特定要素标签归类',
          englishName: 'tdyslxdm',
          width: 120,
          align: 'center',
        },
        {
          label: '差额征税',
          englishName: 'cezs',
          width: 70,
          align: 'center'
        },
        {
          label: '不征税',
          englishName: 'bzs',
          width: 60,
          align: 'center'
        },
        {
          label: '即征即退代码集合',
          englishName: 'jzjtdm',
          width: 'labelWidth',
          align: 'center',
        },
        {
          label: '商品和服务名称',
          englishName: 'sphfwmc',
          width: 300
        },
        {
          label: '商品和服务分类简称',
          englishName: 'sphfwfljc',
          width: 200,
        },
        {
          label: '说明',
          englishName: 'sm',
          width: 200,
        },
        {
          label: '增值税税率',
          englishName: 'zzssl',
        },
        {
          label: '征收率',
          englishName: 'zsl',
        },
        {
          label: '增值税特殊管理',
          englishName: 'zzstsgl',
          width: 'labelWidth',
        },
        {
          label: '增值税政策依据',
          englishName: 'zzszcyj',
          width: 'labelWidth',
        },
        {
          label: '增值税特殊内容代码（增值税减免税政策代码表）',
          englishName: 'zzstsnrdm',
          width: 'labelWidth',
          align: 'center',
        },
        {
          label: '消费税管理',
          englishName: 'xfsgl',
        },
        {
          label: '消费税政策依据',
          englishName: 'xfszcyj',
          width: 'labelWidth',
          align: 'center',
        },
        {
          label: '消费税特殊内容代码',
          englishName: 'xfstsnrdm',
          width: 'labelWidth',
          align: 'center',
        },
        {
          label: '关键字',
          englishName: 'gjz',
          width: 300
        },
        {
          label: '是否汇总项',
          englishName: 'sfhzx',
        },
        {
          label: '对应统计局编码（2011年版）或国民行业代码',
          englishName: 'dytjjbm',
          width: 'labelWidth',
          align: 'center',
        },
        {
          label: '海关进出口商品品目',
          englishName: 'hgjcksppm',
          width: 200
        },
        {
          label: '启用日期',
          englishName: 'qyrq',
        },
        {
          label: '停用日期',
          englishName: 'tyrq',
        },
      ],
      singleDataList: [],

      singleDataList2: [],
      dialogSingleDataListKeyset2: [
        {
          label: '性质',
          englishName: 'csxz',
        },
        {
          label: '税率/征收率',
          englishName: 'slzsl',
          isSlot: true,
          slotName: 'slzsl',
        },
        {
          label: '原税率标志',
          englishName: 'yslbz'
        },
        {
          label: '对应原税率',
          englishName: 'dyysl',
        },
        {
          label: '状态',
          englishName: 'cszt',
        },
        {
          label: '有效期起',
          englishName: 'yxqq',
        },
        {
          label: '有效期止',
          englishName: 'yxqz',
        },
        {
          label: '停用日期',
          englishName: 'tyrq',
        },
      ],
      ListPage: {
        current: 1,
        size: 10,
        total: 0,
      },
      listId: '',
    }
  },
  computed: {},
  methods: {
    changeDate(date) {
      if (date === null) {
        setTimeout(()=>{
          this.dateRange = ['', '']
        },100)
      } else {
        // this.$store.commit('flowInvoice/ChangeFLowForm',{
        //     ...this.$store.state.flowInvoice.flowForm,
        //     startTime: date[0],
        //     endTime: date[1],

        // })
      }
    },
    detailExport() {
      exportDetailList({id: this.lookRow.id})
    },
    detailExport2() {
      exportVmsAvalibleTaxRateLogDetail({
        logBaseId: this.lookRow.id,
      })
    },
    onResize() {
      this.dateRange = ['', '']
      this.onResizeFn()
      // this.date1 = ''
      // this.date2 = ''
      this.getList()
    },
    onSubmit() {
      this.pages.current = 1;

      this.getList()
    },
    getList: throttle(async function () {
      this.loading = true
      let fn =
          this.source == 'baseInfo'
              ? vmsEnterpriseInfoPage
              : this.source == 'taxClass'
                  ? getBasePage
                  : queryVmsAvalibleTaxRateLog

      let {data, code, message} = await fn({
        startTime: this.dateRange[0] || '',
        endTime: this.dateRange[1] || '',
        createUsername: this.searchParams.input1,
        operateStatus: this.searchParams.select1,
        pageNo: this.pages.current,
        pageSize: this.pages.size,
      })
      if (code == 200) {
        this.loading = false

        this.listDetails = data.records
        this.pages.total = data.total
        this.pages.current = data.current
        this.pages.size = data.size
      } else {
        this.loading = false
        // this.$message({
        //   type: 'success',
        //   message: message,
        // })
      }
    }, 500),
    // failFn(row) {
    //   this.$confirm(row.operateMsg, '错误原因', {
    //     showCancelButton: false,
    //     confirmButtonText: '确认'
    //   }).then(data => {

    //   }, err => {
    //   })
    // },
    async look(row) {
      // if (row.operateStatus == '失败') {
      //   return this.failFn(row)
      // }
      this.listId = row.id
      this.lookRow = row
      if (this.source == 'baseInfo') {
        this.baseInfoShow = true

        this.loading = true
        let {data, code, message} = await getDetail(
            {
              id: row.id,
            }
        )
        if (code == 200) {
          // this.detailInfoDetail = {
          //   ...data,
          //   xfsnsrlxdm:"你是电话费生无可恋房间卡拉萨剪发卡累计额无法金卡拉萨电极法卡拉季双打卡飞拉达山卡拉克里斯多夫进度款老规矩卡拉多飞机工卡老大飞机工卡老大飞机克拉管"
          // }
          this.detailInfoDetail = data
        } else {
          // this.$message({
          //   type: 'success',
          //   message: message,
          // })
        }
        this.loading = false
      } else if (this.source == 'taxClass') {
        this.ssflShow = true
        this.ssflAxios(row)
      } else if (this.source == 'availableTax') {
        this.kyslShow = true
        this.kyslAxios(row)
      }
    },
    async ssflAxios(row) {
      this.loading2 = true
      let {data, code, message} = await getBaseDetailPage(
          {
            id: row?.id || this.listId,
            pageNo: this.ListPage.current,
            pageSize: this.ListPage.size
          }
      )
      if (code == 200) {
        this.singleDataList = data.records
        this.ListPage.total = data.total
        this.ListPage.current = data.current
        this.ListPage.size = data.size
      } else {
        // this.$message({
        //   type: 'success',
        //   message: message,
        // })
      }
      this.loading2 = false
    },
    async kyslAxios(row) {
      this.loading2 = true
      let {data, code, message} = await queryVmsAvalibleTaxRateLogDetail(
          {
            logBaseId: row?.id || this.listId,
            pageNo: this.ListPage.current,
            pageSize: this.ListPage.size
          }
      )
      if (code == 200) {
        this.singleDataList2 = data.records
        this.ListPage.total = data.total
        this.ListPage.current = data.current
        this.ListPage.size = data.size
      } else {
        // this.$message({
        //   type: 'success',
        //   message: message,
        // })
      }
      this.loading2 = false
    },
    handlePageSizeChange(val) {
      this.ListPage.size = val
      if (this.source == 'taxClass') {
        this.ssflAxios()
      }
      if (this.source == 'availableTax') {
        this.kyslAxios()
      }
    },
    handlePageCurrentChange(val) {
      this.ListPage.current = val
      if (this.source == 'taxClass') {
        this.ssflAxios()
      }
      if (this.source == 'availableTax') {
        this.kyslAxios()
      }
    },
    filterSet() {
      const filterMap = {
        "/availableTax": ["sjc"],
        "/baseInfo": ["sjc", "logCount"],
      };

      const keysToRemove = filterMap[this.$route.path];

      if (keysToRemove) {
        this.keySet = this.keySet.filter(item => !keysToRemove.includes(item.englishName));
      }
    }
  },
  mounted() {
    this.getList()
    this.filterSet()
  },
  components: {
    tableList,
    popCom,
  },
}
</script>

<style lang="scss" scoped>
.getHistory
:deep
.el-form--inline
.el-form-item__content
.el-select
.el-input
.el-input__inner {
  max-width: 100px;
}
// .operateMsgClass{

// }


.getHistory
:deep
.el-form--inline
.el-form-item__content
.inputClass
.el-input__inner {
  max-width: 100px;
}

.getHistory :deep .el-form--inline .el-form-item__content .el-date-editor {
  width: 240px;
}

.formInline :deep .el-form-item--small {
  margin-bottom: 0px;
}

:deep .el-input--prefix .el-input__inner {
  padding: 0 30px;
}

.getHistory {
  width: 100%;
  height: 100%;

  .dialogClass {
    ::v-deep .vxe-modal--box {
      width: 800px;
    }

    .cardWrap {
      margin-bottom: 20px;
    }

    .qiyeC {
      overflow: hidden;
      white-space: nowrap;
      margin: 0 20px 10px 0;
      width: 100%;
      display: flex;
      display: -ms-flexbox;
      span:nth-child(1) {
        display: block;
        }
    }

    // margin: 0 20px 10px 0;
    &:last-child {
      margin: 0 0px 10px 0;
    }

    .colorGray {
      color: #909399;
      width: 200px;
      display: block;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    // }
  }

  .dialogClass2 {
    // ::v-deep .vxe-modal--box{
    //   width: ;
    // }
    // ::v-deep .vxe-modal--body{
    //   width: 800px;
    // }

  }

  .nsrjbxxhqjlxq ::v-deep .vxe-modal--body {
    min-height: 450px;
    max-height: 450px;
    overflow: auto;
  }
}


</style>
  